namespace Org.Loon.Framework.Xna.Game.Action.Scripting.Pack
{
    using System.Collections.Generic;

    public class PackAnimation
    {

        private string name;

        private List<PackFrame> frames = new List<PackFrame>();

        private bool looped;

        public PackAnimation(string name, bool looped)
        {
            this.name = name;
            this.looped = looped;
        }

        public int Size()
        {
            return frames.Count;
        }

        public PackFrame GetFrame(int index)
        {
            if (frames.Count == 0)
            {
                return frames[0];
            }
            if (looped == true)
            {
                return frames[index % frames.Count];
            }
            else
            {
                if (index >= frames.Count)
                {
                    return frames[frames.Count - 1];
                }
                else
                {
                    return frames[index % frames.Count];
                }
            }
        }

        public string GetName()
        {
            return name;
        }

        public void AddFrame(PackFrame frame)
        {
            frames.Add(frame);
        }

        public bool IsLoop()
        {
            return looped;
        }

        public void SetLoop(bool loop)
        {
            this.looped = loop;
        }

    }
}
